//
//  SendService.m
//  港务移动
//
//  Created by _ADY on 14-6-24.
//  Copyright (c) 2014年 _ADY. All rights reserved.
//

#import "SendService.h"


@implementation SendService

+(void)setSomething
{

}

+(void)customViewDidLoad
{
    [[UINavigationBar appearance] setTintColor:[UIColor blackColor]];
    [[UINavigationBar appearance] setBarTintColor:[UIColor colorWithWhite:.95 alpha:1]];

    [[UITabBar appearance] setBarTintColor:[UIColor colorWithRed:51/255.0 green:51/255.0 blue:51/255.0 alpha:1]];
    [[UITabBar appearance] setSelectedImageTintColor:[UIColor colorWithRed:248/255.0 green:181/255.0 blue:0/255.0 alpha:1]];
}

+(int)setString:(NSString*)aString setSize:(int)aType setWight:(int)labelWight
{
    if ([[NSString stringWithFormat:@"%@",aString] isEqualToString:@"<null>"]) {
        return 10;
    }
    NSDictionary *attribute = @{NSFontAttributeName: [UIFont systemFontOfSize:aType]};
    CGSize totalTextSize = [aString boundingRectWithSize:CGSizeMake(CGFLOAT_MAX,labelWight) options: NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingUsesFontLeading attributes:attribute context:nil].size;

    return totalTextSize.width+10;
}


+(int)setString:(NSString*)aString setSize:(int)aType setHight:(int)labelHight
{
    if ([[NSString stringWithFormat:@"%@",aString] isEqualToString:@"<null>"]) {
        return 10;
    }
    NSDictionary *attribute = @{NSFontAttributeName:[UIFont systemFontOfSize:aType]};
    CGSize totalTextSize = [aString boundingRectWithSize:CGSizeMake(labelHight,CGFLOAT_MAX) options: NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingUsesFontLeading attributes:attribute context:nil].size;
    
    return totalTextSize.height+10;
}

+ (void)setVarUrl:(NSString *)remember
{
    [[NSUserDefaults standardUserDefaults] setObject:remember forKey:@"VarUrlKey"];
    [[NSUserDefaults standardUserDefaults] synchronize];
}

+ (NSString *)VarUrl
{
    NSString *remember = [[NSUserDefaults standardUserDefaults] objectForKey:@"VarUrlKey"];
    return remember;
}

+ (void)setaddress:(NSString *)remember
{
    [[NSUserDefaults standardUserDefaults] setObject:remember forKey:@"addressKey"];
    [[NSUserDefaults standardUserDefaults] synchronize];
}

+ (NSString *)address
{
    NSString *remember = [[NSUserDefaults standardUserDefaults] objectForKey:@"addressKey"];
    return remember;
}

+ (void)setUserAccount:(NSString *)account
{
    [[NSUserDefaults standardUserDefaults] setObject:account forKey:kDefaultUserAccount];
    [[NSUserDefaults standardUserDefaults] synchronize];
}

+ (NSString *)userAccount
{
    NSString *accountId = [[NSUserDefaults standardUserDefaults] objectForKey:kDefaultUserAccount];
    return accountId;
}

+ (void)setPassword:(NSString *)passwd
{
    [[NSUserDefaults standardUserDefaults] setObject:passwd forKey:kDefaultPassword];
    [[NSUserDefaults standardUserDefaults] synchronize];
}

+ (NSString *)password
{
    NSString *password = [[NSUserDefaults standardUserDefaults] objectForKey:kDefaultPassword];
    return password;
}

#pragma mark UIAlertView弹窗
+(void)alerViewMessage:(NSString*)message
{
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:message  delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil];
    [alert show];
}

+(NSString *)htmlEntityDecode:(NSString *)string
{
    string = [string stringByReplacingOccurrencesOfString:@"<DIV>" withString:@""];
    string = [string stringByReplacingOccurrencesOfString:@"</DIV>" withString:@""];
    string = [string stringByReplacingOccurrencesOfString:@"&amp;" withString:@" "];
    string = [string stringByReplacingOccurrencesOfString:@"nbsp;" withString:@" "];
    string = [string stringByReplacingOccurrencesOfString:@"@:lt#" withString:@"<"];
    string = [string stringByReplacingOccurrencesOfString:@"@:gt#" withString:@">"];
    string = [string stringByReplacingOccurrencesOfString:@"&" withString:@""];
    string = [string stringByReplacingOccurrencesOfString:@"#8220;" withString:@"“"];
    string = [string stringByReplacingOccurrencesOfString:@"#8221;" withString:@"”"];
    string = [string stringByReplacingOccurrencesOfString:@"#8230;" withString:@"…"];
    string = [string stringByReplacingOccurrencesOfString:@"#8212;" withString:@"-"];
    string = [string stringByReplacingOccurrencesOfString:@"#8213;" withString:@"-"];
    string = [string stringByReplacingOccurrencesOfString:@"#183;" withString:@"·"];
    string = [string stringByReplacingOccurrencesOfString:@"#8217;" withString:@""];
    string = [string stringByReplacingOccurrencesOfString:@"#8216;" withString:@"'"];
    string = [string stringByReplacingOccurrencesOfString:@"#9312;" withString:@"①"];
    string = [string stringByReplacingOccurrencesOfString:@"#9313;" withString:@"②"];
    string = [string stringByReplacingOccurrencesOfString:@"#9314;" withString:@"③"];
    string = [string stringByReplacingOccurrencesOfString:@"#9315;" withString:@"④"];
    string = [string stringByReplacingOccurrencesOfString:@"#9316;" withString:@"⑤"];
    string = [string stringByReplacingOccurrencesOfString:@"#9317;" withString:@"⑥"];
    string = [string stringByReplacingOccurrencesOfString:@"#9318;" withString:@"⑦"];
    string = [string stringByReplacingOccurrencesOfString:@"#9319;" withString:@"⑧"];
    string = [string stringByReplacingOccurrencesOfString:@"#9320;" withString:@"⑨"];
    
    return string;
}

+(NSString*)webString
{
    NSString * webviewText = @"<style>body{margin:0;background-color:transparent;font:15px/20px Custom-Font-Name}img{width: 300px}</style>";

    return webviewText;
}

#pragma mark 邮箱验证
+ (BOOL)validateEmail:(NSString *)email
{
    NSString *emailRegex = @"[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}";
    NSPredicate *emailTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", emailRegex];
    return [emailTest evaluateWithObject:email];
}

#pragma mark 手机号码验证
+ (BOOL) validateMobile:(NSString *)mobile
{
    //手机号以13， 15，18开头，八个 \d 数字字符
    NSString *phoneRegex = @"^((13[0-9])|(15[^4,\\D])|(18[0,0-9]))\\d{8}$";
    NSPredicate *phoneTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",phoneRegex];
    return [phoneTest evaluateWithObject:mobile];
}

#pragma mark 用户名验证
+ (BOOL) validateUserName:(NSString *)name
{
    NSString *userNameRegex = @"^[A-Za-z0-9]{0,20}+$";
    NSPredicate *userNamePredicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",userNameRegex];
    BOOL B = [userNamePredicate evaluateWithObject:name];
    return B;
}

#pragma mark 密码验证
+ (BOOL) validatePassword:(NSString *)passWord
{
    NSString *passWordRegex = @"^[a-zA-Z0-9]{6,20}+$";
    NSPredicate *passWordPredicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",passWordRegex];
    return [passWordPredicate evaluateWithObject:passWord];
}


#pragma mark 昵称验证
+ (BOOL) validateNickname:(NSString *)nickname
{
    NSString *nicknameRegex = @"^[\u4e00-\u9fa5]{4,8}$";
    NSPredicate *passWordPredicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",nicknameRegex];
    return [passWordPredicate evaluateWithObject:nickname];
}


#pragma mark 身份证号验证
+ (BOOL) validateIdentityCard: (NSString *)identityCard
{
    BOOL flag;
    if (identityCard.length <= 0) {
        flag = NO;
        return flag;
    }
    NSString *regex2 = @"^(\\d{14}|\\d{17})(\\d|[xX])$";
    NSPredicate *identityCardPredicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",regex2];
    return [identityCardPredicate evaluateWithObject:identityCard];
}

#pragma mark 首页大广告(code=AppHomeAdBig) 首单立减广告(code=AppHomeAdMinus) 品牌特卖广告(code=AppHomeAdBrand) 主题馆广告(code=AppHomeAdShopTheme)
+(NSDictionary*)HomepageADs:(NSMutableDictionary*)postDic
{
    NSDictionary* ret = [HttpRequest startSyncJsonHttpRequest:[NSString stringWithFormat:@"%@%@",WEB_URL,kApiHomepageADs] setUserData:postDic];
    return ret;
}
#pragma mark 秒杀场次列表(code=AppHomeActPanicBuy)
+(NSDictionary*)HomepageSecKill:(NSMutableDictionary*)postDic
{
    NSDictionary* ret = [HttpRequest startSyncJsonHttpRequest:[NSString stringWithFormat:@"%@%@",WEB_URL,kApiHomepageSecKill] setUserData:postDic];
    return ret;
}
#pragma mark 场次秒杀商品列表
+(NSDictionary*)GetSecKillProductListByPlay:(NSMutableDictionary*)postDic
{
    NSDictionary* ret = [HttpRequest startSyncJsonHttpRequest:[NSString stringWithFormat:@"%@%@",WEB_URL,kApiGetSecKillProductListByPlay] setUserData:postDic];
    return ret;
}
#pragma mark 首单立减活动
+(NSDictionary*)ActiveProducts:(NSMutableDictionary*)postDic
{
    NSDictionary* ret = [HttpRequest startSyncJsonHttpRequest:[NSString stringWithFormat:@"%@%@",WEB_URL,kApiActiveProductsy] setUserData:postDic];
    return ret;
}

#pragma mark 新品推荐橱窗商品列表(code=AppHomeLayNewPop) 精品推荐橱窗商品列表(code=AppHomeLayGoodPop)
+(NSDictionary*)GetWindowLayoutProductList:(NSMutableDictionary*)postDic
{
    NSDictionary* ret = [HttpRequest startSyncJsonHttpRequest:[NSString stringWithFormat:@"%@%@",WEB_URL,kApiGetWindowLayoutProductList] setUserData:postDic];
    return ret;
}

#pragma mark 首页广告
+(NSDictionary*)HomepageAD
{
    NSDictionary* ret = [HttpRequest startSyncHttpRequest:[NSString stringWithFormat:@"%@%@",WEB_URL,kApiHomepageAD]];
    return ret;
}
#pragma mark 商品列表，今日特惠接口
+(NSDictionary*)HomepageTodaySales
{
    NSDictionary* ret = [HttpRequest startSyncHttpRequest:[NSString stringWithFormat:@"%@%@",WEB_URL,KApiHomepageTodaySales]];
    return ret;
}

#pragma mark 精品推荐接口
+(NSDictionary*)HomepageFeaturedProducts
{
    NSDictionary* ret = [HttpRequest startSyncHttpRequest:[NSString stringWithFormat:@"%@%@",WEB_URL,KApiHomepageFeaturedProducts]];
    return ret;
}

#pragma mark 商品列表
+(NSDictionary*)HomepageCatalogProducts:(NSMutableDictionary *)postData
{
    NSDictionary* ret = [HttpRequest startSyncJsonHttpRequest:[NSString stringWithFormat:@"%@%@",WEB_URL,KApiHomepageCatalogProducts] setUserData:postData];
    return ret;
}

#pragma mark 商品详情
+(NSDictionary*)GetDetailProduct:(NSMutableDictionary *)postData
{
    NSDictionary* ret = [HttpRequest startSyncJsonHttpRequest:[NSString stringWithFormat:@"%@%@",WEB_URL,KApiGetDetailProduct] setUserData:postData];
    return ret;
}

#pragma mark 登陆
+(NSDictionary*)Login:(NSMutableDictionary *)postData
{
    NSDictionary* ret = [HttpRequest startSyncJsonHttpRequest:[NSString stringWithFormat:@"%@%@",WEB_URL,KApiLogin] setUserData:postData];
    return ret;
}

#pragma mark 获取购物车列表
+(NSDictionary*)cart
{
    NSDictionary* ret = [HttpRequest startSyncHttpRequest:[NSString stringWithFormat:@"%@%@",WEB_URL,KApicart] ];
    return ret;
    
//    NSURL* url = [NSURL URLWithString:[[NSString stringWithFormat:@"%@%@",WEB_URL,KApicart] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
//    
//    return [self setUrl:url setNSMutableData:nil];
}

#pragma mark 获取商品接口为ManageInventoryMethodId = 2  价格、库存等
+(NSDictionary*)GetProductInfoByAttribute:(NSMutableDictionary *)postData
{
    
    NSDictionary* ret = [HttpRequest startSyncJsonHttpRequest:[NSString stringWithFormat:@"%@%@",WEB_URL,KApiGetProductInfoByAttribute] setUserData:postData];
    return ret;
}

#pragma mark 获取商品接口为ManageInventoryMethodId = 2  价格、库存等
+(NSDictionary*)GetProductInfoByAttribute:(NSString*)mid source:(NSMutableArray*)source
{
    NSData* jsonData =[NSJSONSerialization dataWithJSONObject:source options:NSJSONWritingPrettyPrinted error:nil];
    NSString* text =[[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];

    NSString *urlStr = [[NSString stringWithFormat:@"%@%@",WEB_URL,KApiGetProductInfoByAttribute] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    NSURL *url = [NSURL URLWithString:urlStr];
    ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
    [request setUseKeychainPersistence:YES];
    [request setPostValue:mid forKey:@"productId"];
    [request setPostValue:text forKey:@"source"];
    [request setRequestMethod:@"POST"];
    request.useCookiePersistence = YES;
    NSArray *paths=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES);
    NSString *path=[paths  objectAtIndex:0];
    NSString *filename=[path stringByAppendingPathComponent:@"cookie.plist"];
    NSDictionary *remData= [NSDictionary dictionaryWithContentsOfFile:filename];
    if (remData != nil)
    {
        NSHTTPCookie *cookie = [[NSHTTPCookie alloc] initWithProperties:remData];
        [request setRequestCookies:[NSMutableArray arrayWithObject:cookie]];
    }
    [request startSynchronous];
    
    
    NSData* resData = [request responseData];
    JSONDecoder *jd = [[JSONDecoder alloc] init];
    NSDictionary *ret = [jd objectWithData:resData];
    return ret;

}

#pragma mark 商品评价列表
+(NSDictionary*)ReviewsPage:(NSString*)mid pageNumber:(int)pageNumber
{
    NSString *urlStr = [[NSString stringWithFormat:@"%@%@",WEB_URL,KApiReviewsPage] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    NSURL *url = [NSURL URLWithString:urlStr];
    ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
    [request setUseKeychainPersistence:YES];
    [request setPostValue:mid forKey:@"productId"];
    [request setPostValue:[NSNumber numberWithInt:pageNumber] forKey:@"pageNumber"];
    [request setPostValue:[NSNumber numberWithInt:itemLabel] forKey:@"pageSize"];
    [request setRequestMethod:@"POST"];
    request.useCookiePersistence = YES;
    NSArray *paths=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES);
    NSString *path=[paths  objectAtIndex:0];
    NSString *filename=[path stringByAppendingPathComponent:@"cookie.plist"];
    NSDictionary *remData= [NSDictionary dictionaryWithContentsOfFile:filename];
    if (remData != nil)
    {
        NSHTTPCookie *cookie = [[NSHTTPCookie alloc] initWithProperties:remData];
        [request setRequestCookies:[NSMutableArray arrayWithObject:cookie]];
    }
    [request startSynchronous];
    
    
    NSData* resData = [request responseData];
    JSONDecoder *jd = [[JSONDecoder alloc] init];
    NSDictionary *ret = [jd objectWithData:resData];
    return ret;
}
#pragma mark 猜你喜欢
+(NSDictionary*)InterestingProducts
{
    NSDictionary* ret = [HttpRequest startSyncHttpRequest:[NSString stringWithFormat:@"%@%@",WEB_URL,KApiInterestingProductse] ];
    return ret;
}
#pragma mark 搜索
+(NSDictionary*)GetSearchProducts:(NSMutableDictionary *)postData
{
    
    NSDictionary* ret = [HttpRequest startSyncJsonHttpRequest:[NSString stringWithFormat:@"%@%@",WEB_URL,KApiGetSearchProducts] setUserData:postData];
    return ret;
}

#pragma mark 获取省份列表
+(NSDictionary*)GetStatesByCountryId
{
    NSDictionary* ret = [HttpRequest startSyncHttpRequest:[NSString stringWithFormat:@"%@%@",WEB_URL,KApiGetStatesByCountryId] ];
    return ret;
}

#pragma mark 获取城市列表接口
+(NSDictionary*)GetCityByProvinceId:(NSMutableDictionary *)postData
{
    
    NSDictionary* ret = [HttpRequest startSyncJsonHttpRequest:[NSString stringWithFormat:@"%@%@",WEB_URL,KApiGetCityByProvinceId] setUserData:postData];
    return ret;
}

#pragma mark 获取县区列表接口
+(NSDictionary*)GetDistrictByCityId:(NSMutableDictionary *)postData
{
    
    NSDictionary* ret = [HttpRequest startSyncJsonHttpRequest:[NSString stringWithFormat:@"%@%@",WEB_URL,KApiGetDistrictByCityId] setUserData:postData];
    return ret;
}

#pragma mark 获取街道列表接口
+(NSDictionary*)GetStreetByDistrictId:(NSMutableDictionary *)postData
{
    
    NSDictionary* ret = [HttpRequest startSyncJsonHttpRequest:[NSString stringWithFormat:@"%@%@",WEB_URL,KApiGetStreetByDistrictId] setUserData:postData];
    return ret;
}
/*
 当商品需要进行规格属性的选择时 参数还需要加上 &product_attribute_商品ID_商品规格1ID_规格1ID=规格值1&product_attribute_商品ID_商品规 格2ID_规格2ID=规格值2...
 
 加入购物车接口
 参数实例：productId=64&shoppingCartTypeId=1&addtocart_64.EnteredQuantity=1
 参数格式：productId=商品ID&shoppingCartTypeId=1&addtocart_商品ID.EnteredQuantity=加入购物车的数量
 
 加入收藏夹接口
 参数实例：productId=64&shoppingCartTypeId=2
 参数格式：productId=商品ID&shoppingCartTypeId=2
 */
#pragma mark 商品详情页加入购物车接口 商品详情页加入收藏夹接口
+(NSDictionary*)AddProductToCart_Details:(NSMutableDictionary *)postData
{
    
    NSDictionary* ret = [HttpRequest startSyncJsonHttpRequest:[NSString stringWithFormat:@"%@%@",WEB_URL,KApiAddProductToCart_Details] setUserData:postData];
    return ret;
}

+(NSDictionary*)startGoRequest:(NSString *)urlStr setUserData:(NSMutableDictionary*)postData
{
    NSURL *url = [NSURL URLWithString:urlStr];
    ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
    [request setUseKeychainPersistence:YES];
    
    NSArray *keys = [postData allKeys];
    
    for (NSString *key in keys)
    {
        NSRange range = [key rangeOfString:@"removefromcart"];
        if (range.length >0)
            [request addPostValue:[postData objectForKey:key] forKey:@"removefromcart"];
        else
        {
            NSRange range1 = [key rangeOfString:@"useAct"];
            if (range1.length >0)
                [request addPostValue:[postData objectForKey:key] forKey:@"useAct"];
            else
                [request setPostValue:[postData objectForKey:key] forKey:key];
        }
        
    }
    
    [request setRequestMethod:@"POST"];
    request.useCookiePersistence = YES;
    NSArray *paths=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES);
    NSString *path=[paths  objectAtIndex:0];
    NSString *filename=[path stringByAppendingPathComponent:@"cookie.plist"];
    NSDictionary *remData= [NSDictionary dictionaryWithContentsOfFile:filename];
    if (remData != nil)
    {
        NSHTTPCookie *cookie = [[NSHTTPCookie alloc] initWithProperties:remData];
        [request setRequestCookies:[NSMutableArray arrayWithObject:cookie]];
    }
    [request startSynchronous];
    
    
    NSData* resData = [request responseData];
    JSONDecoder *jd = [[JSONDecoder alloc] init];
    NSDictionary *ret = [jd objectWithData:resData];
    return ret;
}

#pragma mark 商品详情页加入购物车接口 商品详情页加入收藏夹接口
+(NSDictionary*)AddProductToCart_DetailsTwo:(NSMutableDictionary*)postData
{
    NSString *urlStr = [[NSString stringWithFormat:@"%@%@",WEB_URL,KApiAddProductToCart_Details] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

    NSDictionary* ret = [self startGoRequest:urlStr setUserData:postData];
    return ret;

}

#pragma mark 商品详情取消收藏
+(NSDictionary*)DelWishlistByProductId:(NSMutableDictionary*)postData
{
    NSString *urlStr = [[NSString stringWithFormat:@"%@%@",WEB_URL,KApiDelWishlistByProductId] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    
    NSDictionary* ret = [self startGoRequest:urlStr setUserData:postData];
    return ret;
    
}

#pragma mark 购物车加入收藏夹接口 购物车或收藏夹类型ID：1表示从收藏夹加入购物车，2表示从购物车加入收藏夹
+(NSDictionary*)AddProductToCart_ShoppingCart:(NSMutableDictionary*)postData
{
    NSString *urlStr = [[NSString stringWithFormat:@"%@%@",WEB_URL,KApiAddProductToCart_ShoppingCart] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    
    NSDictionary* ret = [self startGoRequest:urlStr setUserData:postData];
    return ret;
    
}

#pragma mark 商品批量加入收藏夹接口
+(NSDictionary*)AddItemsToWishlistFromCart:(NSMutableDictionary*)postData
{
    NSString *urlStr = [[NSString stringWithFormat:@"%@%@",WEB_URL,KApiAddItemsToWishlistFromCart] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    
    NSDictionary* ret = [self startGoRequest:urlStr setUserData:postData];
    return ret;
    
}


#pragma mark 更新购物车接口
+(NSDictionary*)UpdateCart:(NSMutableDictionary*)postData
{
    NSString *urlStr = [[NSString stringWithFormat:@"%@%@",WEB_URL,KApiUpdateCart] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    
    NSDictionary* ret = [self startGoRequest:urlStr setUserData:postData];
    return ret;
    
}

#pragma mark 提交订单接口
+(NSDictionary*)ConfirmOrder:(NSMutableDictionary*)postData
{
    NSString *urlStr = [[NSString stringWithFormat:@"%@%@",WEB_URL,KApiConfirmOrder] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    
    NSDictionary* ret = [self startGoRequest:urlStr setUserData:postData];
    return ret;
    
}

#pragma mark 结算购物车接口
+(NSDictionary*)CheckoutOrder:(NSMutableDictionary*)postData
{
    NSString *urlStr = [[NSString stringWithFormat:@"%@%@",WEB_URL,KApiCheckoutOrder] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    
    NSDictionary* ret = [self startGoRequest:urlStr setUserData:postData];
    return ret;
    
}

#pragma mark 获取收货地址列表
+(NSDictionary*)Addresses
{
    NSDictionary* ret = [HttpRequest startSyncHttpRequest:[NSString stringWithFormat:@"%@%@",WEB_URL,KApiAddresses] ];
    return ret;
    
}

#pragma mark 添加收货地址
+(NSDictionary*)AddressAdd:(NSMutableDictionary*)postData
{
    NSString *urlStr = [[NSString stringWithFormat:@"%@%@",WEB_URL,KApiAddressAdd] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    
    NSDictionary* ret = [self startGoRequest:urlStr setUserData:postData];
    return ret;
    
}

#pragma mark 根据收货地址ID获取收货地址
+(NSDictionary*)AddressGet:(NSMutableDictionary*)postData
{
    NSString *urlStr = [[NSString stringWithFormat:@"%@%@",WEB_URL,KApiAddressGet] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    
    NSDictionary* ret = [self startGoRequest:urlStr setUserData:postData];
    return ret;
    
}

#pragma mark 编辑保存收货地址
+(NSDictionary*)AddressEdit:(NSMutableDictionary*)postData
{
    NSString *urlStr = [[NSString stringWithFormat:@"%@%@",WEB_URL,KApiAddressEdit] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    
    NSDictionary* ret = [self startGoRequest:urlStr setUserData:postData];
    return ret;
    
}

#pragma mark 根据收货地址ID删除收货地址
+(NSDictionary*)AddressDelete:(NSMutableDictionary*)postData
{
    NSString *urlStr = [[NSString stringWithFormat:@"%@%@",WEB_URL,KApiAddressDelete] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    
    NSDictionary* ret = [self startGoRequest:urlStr setUserData:postData];
    return ret;
    
}

#pragma mark 根据收货地址ID设置默认收货地址
+(NSDictionary*)SelectShippingAddress:(NSMutableDictionary*)postData
{
    NSString *urlStr = [[NSString stringWithFormat:@"%@%@",WEB_URL,KApiSelectShippingAddress] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    
    NSDictionary* ret = [self startGoRequest:urlStr setUserData:postData];
    return ret;
    
}

#pragma mark 商品分类接口
+(NSDictionary*)GetStoreCategories
{
    NSDictionary* ret = [HttpRequest startSyncHttpRequest:[NSString stringWithFormat:@"%@%@",WEB_URL,KApiGetStoreCategories] ];
    return ret;
}

#pragma mark 店铺基本信息
+(NSDictionary*)GetShopInfoById:(NSMutableDictionary *)postData
{
    
    NSDictionary* ret = [HttpRequest startSyncJsonHttpRequest:[NSString stringWithFormat:@"%@%@",WEB_URL,KApiGetShopInfoById] setUserData:postData];
    return ret;
}

#pragma mark 店铺列表
+(NSDictionary*)GetSearchShops:(NSMutableDictionary *)postData
{
    
    NSDictionary* ret = [HttpRequest startSyncJsonHttpRequest:[NSString stringWithFormat:@"%@%@",WEB_URL,KApiGetSearchShops] setUserData:postData];
    return ret;
}

#pragma mark 店铺分类接口
+(NSDictionary*)GetShopCategoriesById:(NSMutableDictionary *)postData
{
    
    NSDictionary* ret = [HttpRequest startSyncJsonHttpRequest:[NSString stringWithFormat:@"%@%@",WEB_URL,KApiGetShopCategoriesById] setUserData:postData];
    return ret;
}

#pragma mark 店铺商品列表
+(NSDictionary*)GetProductsByShopCategoryId:(NSMutableDictionary *)postData
{
    
    NSDictionary* ret = [HttpRequest startSyncJsonHttpRequest:[NSString stringWithFormat:@"%@%@",WEB_URL,KApiGetProductsByShopCategoryId] setUserData:postData];
    return ret;
}

#pragma mark 订单列表
+(NSDictionary*)GetSimpleOrders:(NSMutableDictionary *)postData
{
    
    NSDictionary* ret = [HttpRequest startSyncJsonHttpRequest:[NSString stringWithFormat:@"%@%@",WEB_URL,KApiGetSimpleOrders] setUserData:postData];
    return ret;
}

#pragma mark 订单明细列表
+(NSDictionary*)GetOrderDetailById:(NSMutableDictionary *)postData
{
    
    NSDictionary* ret = [HttpRequest startSyncJsonHttpRequest:[NSString stringWithFormat:@"%@%@",WEB_URL,KApiGetOrderDetailById] setUserData:postData];
    return ret;
}

#pragma mark 订单详情
+(NSDictionary*)GetOrderModelById:(NSMutableDictionary *)postData
{
    
    NSDictionary* ret = [HttpRequest startSyncJsonHttpRequest:[NSString stringWithFormat:@"%@%@",WEB_URL,KApiGetOrderModelById] setUserData:postData];
    return ret;
}

#pragma mark 获取某类订单数量
+(NSDictionary*)GetOrderNum:(NSMutableDictionary *)postData
{
    
    NSDictionary* ret = [HttpRequest startSyncJsonHttpRequest:[NSString stringWithFormat:@"%@%@",WEB_URL,KApiGetOrderNum] setUserData:postData];
    return ret;
}

#pragma mark 确认收货
+(NSDictionary*)SetAsDelivered:(NSMutableDictionary *)postData
{
    
    NSDictionary* ret = [HttpRequest startSyncJsonHttpRequest:[NSString stringWithFormat:@"%@%@",WEB_URL,KApiSetAsDelivered] setUserData:postData];
    return ret;
}

#pragma mark 取消订单
+(NSDictionary*)CancelOrder:(NSMutableDictionary *)postData
{
    
    NSDictionary* ret = [HttpRequest startSyncJsonHttpRequest:[NSString stringWithFormat:@"%@%@",WEB_URL,KApiCancelOrder] setUserData:postData];
    return ret;
}

#pragma mark 客户订单记录删除
+(NSDictionary*)SetCustomerDeleteStatus:(NSMutableDictionary *)postData
{
    
    NSDictionary* ret = [HttpRequest startSyncJsonHttpRequest:[NSString stringWithFormat:@"%@%@",WEB_URL,KApiSetCustomerDeleteStatus] setUserData:postData];
    return ret;
}

+(NSDictionary*)setUrl:(NSURL*)url setNSMutableData:(NSMutableData*)tempJsonData
{
    ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
    [request addRequestHeader:@"Content-Type" value:@"application/json; encoding=utf-8"];
    [request addRequestHeader:@"Accept" value:@"application/json"];
    [request setRequestMethod:@"POST"];
    [request setPostBody:tempJsonData];
    request.useCookiePersistence = YES;
    NSArray *paths=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES);
    NSString *path=[paths  objectAtIndex:0];
    NSString *filename=[path stringByAppendingPathComponent:@"cookie.plist"];
    NSDictionary *remData= [NSDictionary dictionaryWithContentsOfFile:filename];
    if (remData != nil && [[NSUserDefaults standardUserDefaults] boolForKey:@"isLoginKey"])
    {
        NSHTTPCookie *cookie = [[NSHTTPCookie alloc] initWithProperties:remData];
        [request setRequestCookies:[NSMutableArray arrayWithObject:cookie]];
    }
    [request startSynchronous];
    
    NSData* resData = [request responseData];
    JSONDecoder *jd = [[JSONDecoder alloc] init];
    NSDictionary *ret = [jd objectWithData:resData];
    
    return ret;
}
#pragma mark 手机注册
+(NSDictionary*)CustomerRegister:(NSMutableDictionary *)postData
{
    
    if ([NSJSONSerialization isValidJSONObject:postData])
    {
        NSData *jsonData = [NSJSONSerialization dataWithJSONObject:postData options:NSJSONWritingPrettyPrinted error:nil];
        NSMutableData *tempJsonData = [NSMutableData dataWithData:jsonData];
        
        NSURL* url = [NSURL URLWithString:[[NSString stringWithFormat:@"%@%@",WEB_URL,KApiCustomerRegister] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];

        return [self setUrl:url setNSMutableData:tempJsonData];

    }
    return nil;
    
}

#pragma mark 个人中心-评价
+(NSDictionary*)ProductReviewsAdd:(NSMutableDictionary *)postData
{
    
    if ([NSJSONSerialization isValidJSONObject:postData])
    {
        NSData *jsonData = [NSJSONSerialization dataWithJSONObject:postData options:NSJSONWritingPrettyPrinted error:nil];
        NSMutableData *tempJsonData = [NSMutableData dataWithData:jsonData];
        
        NSURL* url = [NSURL URLWithString:[[NSString stringWithFormat:@"%@%@",WEB_URL,KApiProductReviewsAdd] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
        
        return [self setUrl:url setNSMutableData:tempJsonData];
        
    }
    return nil;
    
}

#pragma mark 个人中心-晒单
+(NSDictionary*)SharePictureAdd:(NSMutableDictionary *)postData
{
    
    if ([NSJSONSerialization isValidJSONObject:postData])
    {
        NSData *jsonData = [NSJSONSerialization dataWithJSONObject:postData options:NSJSONWritingPrettyPrinted error:nil];
        NSMutableData *tempJsonData = [NSMutableData dataWithData:jsonData];
        
        NSURL* url = [NSURL URLWithString:[[NSString stringWithFormat:@"%@%@",WEB_URL,KApiSharePictureAdd] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
        
        return [self setUrl:url setNSMutableData:tempJsonData];
        
    }
    return nil;
    
}

#pragma mark 订单支付接口
+(NSDictionary*)GetOrderPayingUrl:(NSMutableDictionary *)postData
{
    /*参数： orderId int 类型返回数据：
     1、{"Entity":null,"Result":"error","Message":"你没有权限或改订单已被删除！"}
     2、{"Entity":null,"Result":"success","Message":null}*/
    NSDictionary* ret = [HttpRequest startSyncJsonHttpRequest:[NSString stringWithFormat:@"%@%@",WEB_URL,KApiGetOrderPayingUrl] setUserData:postData];
    return ret;
}


#pragma mark 个人信息接口
+(NSDictionary*)SaveInfo:(NSMutableDictionary *)postData
{
    
    if ([NSJSONSerialization isValidJSONObject:postData])
    {
        NSData *jsonData = [NSJSONSerialization dataWithJSONObject:postData options:NSJSONWritingPrettyPrinted error:nil];
        NSMutableData *tempJsonData = [NSMutableData dataWithData:jsonData];
        
        NSURL* url = [NSURL URLWithString:[[NSString stringWithFormat:@"%@%@",WEB_URL,KApiSaveInfo] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
        
        return [self setUrl:url setNSMutableData:tempJsonData];
        
    }
    return nil;
    
}

#pragma mark 修改个人密码接口
+(NSDictionary*)PasswordChange:(NSMutableDictionary *)postData
{
    
    if ([NSJSONSerialization isValidJSONObject:postData])
    {
        NSData *jsonData = [NSJSONSerialization dataWithJSONObject:postData options:NSJSONWritingPrettyPrinted error:nil];
        NSMutableData *tempJsonData = [NSMutableData dataWithData:jsonData];
        
        NSURL* url = [NSURL URLWithString:[[NSString stringWithFormat:@"%@%@",WEB_URL,KApiPasswordChange] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
        
        return [self setUrl:url setNSMutableData:tempJsonData];
        
    }
    return nil;
    
}


#pragma mark 获取用户购物车收藏夹数量接口
+(NSDictionary*)GetShoppingCartCount
{
    NSURL* url = [NSURL URLWithString:[[NSString stringWithFormat:@"%@%@",WEB_URL,KApiGetShoppingCartCount] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
        
    return [self setUrl:url setNSMutableData:nil];
    
}

#pragma mark 获取收藏夹列表
+(NSDictionary*)Wishlist:(NSMutableDictionary *)postData
{
    //command.PageNumber=当前页数&command.PageSize=分页大小
    NSDictionary* ret = [HttpRequest startSyncJsonHttpRequest:[NSString stringWithFormat:@"%@%@",WEB_URL,KApiWishlist] setUserData:postData];
    return ret;
}

#pragma mark 获取收藏店铺列表
+(NSDictionary*)FavoriteShopList:(NSMutableDictionary *)postData
{
    //command.PageNumber=当前页数&command.PageSize=分页大小
    if ([NSJSONSerialization isValidJSONObject:postData])
    {
        NSData *jsonData = [NSJSONSerialization dataWithJSONObject:postData options:NSJSONWritingPrettyPrinted error:nil];
        NSMutableData *tempJsonData = [NSMutableData dataWithData:jsonData];
        
        NSURL* url = [NSURL URLWithString:[[NSString stringWithFormat:@"%@%@",WEB_URL,KApiFavoriteShopList] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
        
        return [self setUrl:url setNSMutableData:tempJsonData];
        
    }
    return nil;
}

#pragma mark 摇一摇
+(NSDictionary*)Lottery:(NSMutableDictionary *)postData
{
    NSURL* url = [NSURL URLWithString:[[NSString stringWithFormat:@"%@%@",WEB_URL,KApiLottery] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
        
    return [self setUrl:url setNSMutableData:nil];
}

#pragma mark 摇一摇规则
+(NSDictionary*)LotteryInfo:(NSMutableDictionary *)postData
{
    NSURL* url = [NSURL URLWithString:[[NSString stringWithFormat:@"%@%@",WEB_URL,KApiLotteryInfo] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
        
    return [self setUrl:url setNSMutableData:nil];

}

#pragma mark 我的优惠券接口
+(NSDictionary*)MyCoupon:(NSMutableDictionary *)postData
{
    if ([NSJSONSerialization isValidJSONObject:postData])
    {
        NSData *jsonData = [NSJSONSerialization dataWithJSONObject:postData options:NSJSONWritingPrettyPrinted error:nil];
        NSMutableData *tempJsonData = [NSMutableData dataWithData:jsonData];
        
        NSURL* url = [NSURL URLWithString:[[NSString stringWithFormat:@"%@%@",WEB_URL,KApiMyCoupon] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
        
        return [self setUrl:url setNSMutableData:tempJsonData];
        
    }
    return nil;
}

#pragma mark 领取优惠券接口
+(NSDictionary*)ReceiveCoupons:(NSMutableDictionary *)postData
{
    if ([NSJSONSerialization isValidJSONObject:postData])
    {
        NSData *jsonData = [NSJSONSerialization dataWithJSONObject:postData options:NSJSONWritingPrettyPrinted error:nil];
        NSMutableData *tempJsonData = [NSMutableData dataWithData:jsonData];
        
        NSURL* url = [NSURL URLWithString:[[NSString stringWithFormat:@"%@%@",WEB_URL,KApiReceiveCoupons] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
        
        return [self setUrl:url setNSMutableData:tempJsonData];
        
    }
    return nil;
}
#pragma mark 领取某优惠券
+(NSDictionary*)ImmediatelyReceive:(NSMutableDictionary *)postData
{
    if ([NSJSONSerialization isValidJSONObject:postData])
    {
        NSData *jsonData = [NSJSONSerialization dataWithJSONObject:postData options:NSJSONWritingPrettyPrinted error:nil];
        NSMutableData *tempJsonData = [NSMutableData dataWithData:jsonData];
        
        NSURL* url = [NSURL URLWithString:[[NSString stringWithFormat:@"%@%@",WEB_URL,KApiImmediatelyReceive] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
        
        return [self setUrl:url setNSMutableData:tempJsonData];
        
    }
    return nil;
}

#pragma mark 金元宝列表
+(NSDictionary*)MyGoldIngot:(NSMutableDictionary *)postData
{
    if ([NSJSONSerialization isValidJSONObject:postData])
    {
        NSData *jsonData = [NSJSONSerialization dataWithJSONObject:postData options:NSJSONWritingPrettyPrinted error:nil];
        NSMutableData *tempJsonData = [NSMutableData dataWithData:jsonData];
        
        NSURL* url = [NSURL URLWithString:[[NSString stringWithFormat:@"%@%@",WEB_URL,KApiMyGoldIngot] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
        
        return [self setUrl:url setNSMutableData:tempJsonData];
        
    }
    return nil;
}

#pragma mark 银元宝列表
+(NSDictionary*)MySilverIngot:(NSMutableDictionary *)postData
{
    if ([NSJSONSerialization isValidJSONObject:postData])
    {
        NSData *jsonData = [NSJSONSerialization dataWithJSONObject:postData options:NSJSONWritingPrettyPrinted error:nil];
        NSMutableData *tempJsonData = [NSMutableData dataWithData:jsonData];
        
        NSURL* url = [NSURL URLWithString:[[NSString stringWithFormat:@"%@%@",WEB_URL,KApiMySilverIngot] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
        
        return [self setUrl:url setNSMutableData:tempJsonData];
        
    }
    return nil;
}

#pragma mark 返利列表
+(NSDictionary*)CustomerReferralFeeRecordList:(NSMutableDictionary *)postData
{
    if ([NSJSONSerialization isValidJSONObject:postData])
    {
        NSData *jsonData = [NSJSONSerialization dataWithJSONObject:postData options:NSJSONWritingPrettyPrinted error:nil];
        NSMutableData *tempJsonData = [NSMutableData dataWithData:jsonData];
        
        NSURL* url = [NSURL URLWithString:[[NSString stringWithFormat:@"%@%@",WEB_URL,KApiCustomerReferralFeeRecordList] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
        
        return [self setUrl:url setNSMutableData:tempJsonData];
        
    }
    return nil;
}

#pragma mark 更新接口
+(NSDictionary*)CheckVer:(NSMutableDictionary *)postData
{
    //command.PageNumber=当前页数&command.PageSize=分页大小
    NSDictionary* ret = [HttpRequest startSyncJsonHttpRequest:[NSString stringWithFormat:@"%@%@",WEB_URL,KApiCheckVer] setUserData:postData];
    return ret;
}

#pragma mark 店铺收藏
+(NSDictionary*)FavoriteShopInsert:(NSMutableDictionary *)postData
{
    if ([NSJSONSerialization isValidJSONObject:postData])
    {
        NSData *jsonData = [NSJSONSerialization dataWithJSONObject:postData options:NSJSONWritingPrettyPrinted error:nil];
        NSMutableData *tempJsonData = [NSMutableData dataWithData:jsonData];
        
        NSURL* url = [NSURL URLWithString:[[NSString stringWithFormat:@"%@%@",WEB_URL,KApiFavoriteShopInsert] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
        
        return [self setUrl:url setNSMutableData:tempJsonData];
        
    }
    return nil;
}
#pragma mark 取消店铺收藏
+(NSDictionary*)FavoriteShopDelete:(NSMutableDictionary *)postData
{
    if ([NSJSONSerialization isValidJSONObject:postData])
    {
        NSData *jsonData = [NSJSONSerialization dataWithJSONObject:postData options:NSJSONWritingPrettyPrinted error:nil];
        NSMutableData *tempJsonData = [NSMutableData dataWithData:jsonData];
        
        NSURL* url = [NSURL URLWithString:[[NSString stringWithFormat:@"%@%@",WEB_URL,KApiFavoriteShopDelete] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
        
        return [self setUrl:url setNSMutableData:tempJsonData];
        
    }
    return nil;
}

#define KApiAccountConfirmNext @"/ApiCustomer/AccountConfirmNext?"
//发送短信到手机
#define KApiSendSms @"/ApiCustomer/SendSms?"
//短信验证码 验证
#define KApiPasswordRecoverySendPhone @"/ApiCustomer/PasswordRecoverySendPhone?"
//修改密码
#define KApiPasswordRecoveryConfirmPhonePOST @"/ApiCustomer/PasswordRecoveryConfirmPhonePOST?"

@end
